package inspur.dao;

import inspur.common.ConnectionUtils;
import inspur.entity.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class RegDao {
    Connection conn=null;
    PreparedStatement pstm=null;
    ResultSet rs=null;



    //注册用户
    public int reg(User user){

        //得到数据库对象
        conn= ConnectionUtils.getConnection();

        int flag=0;//用户名不存在
        try {
            //发送sql文


            String sql="INSERT  INTO ";
            pstm= conn.prepareStatement(sql);
            pstm.setString(1, user.getId()
            );
            rs= pstm.executeQuery();

            //处理结果集
            while(rs.next()){
                String temp=rs.getString("password");
                if(temp.equals(user.getPassword())){
                    //用户名和密码都正确
                    flag=2;

                }else{
                    //密码不正确
                    flag=1;
                }
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }finally{

            //释放资源
            ConnectionUtils.close(rs, pstm, conn);
        }
        return flag;

    }
}
